package net.huazai.config;

import lombok.extern.slf4j.Slf4j;
import net.huazai.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 11987
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer{

    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器
        registry.addInterceptor(loginInterceptor())
                // 需要拦截的路径
                .addPathPatterns("/api/user/*/**", "/api/address/*/**")
                // 不需要拦截的路径
                .excludePathPatterns("/api/user/*/getImgCaptcha"
                        , "/api/user/*/sendCode",
                        "/api/user/*/register"
                        ,"/api/user/*/login"
                        ,"/api/user/*/upload");
    }
}

